import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Table, Tag, Space, Button, Popconfirm } from 'antd';
import action from "../../../store/action";
import Home_edit from '../Home_edit';
import { Link } from 'react-router-dom';



class index extends React.Component {
    constructor() {
        super();

    }
    componentWillMount() {
        this.handel_getData();
    }
    render() {
        const columns = [
            {
                title: '单位名称',
                dataIndex: 'pname',
                key: 'pname',
                render: text => <a>{text}</a>,
                width: 230
            },
            {
                title: '邮编',
                dataIndex: 'postalCode',
                key: 'postalCode',
                width: 120

            },
            {
                title: '地址',
                dataIndex: 'address',
                key: 'address',
                width: 200
            },
            {
                title: '联系电话',
                key: 'tel',
                dataIndex: 'tel',
                width: 150
            },
            {
                title: '传真',
                key: 'fax',
                dataIndex: 'fax',
                width: 150
            },
            {
                title: '主页',
                key: 'homePage',
                dataIndex: 'homePage',
                width: 200
            },
            {
                title: '邮箱',
                key: 'email',
                dataIndex: 'email',
                width: 150
            },
            {
                title: '操作',
                key: 'action',
                width: 150,
                render: (text, record, index) => {
                    return <Space size="middle">
                        <Link to='/admin/Home_edit'><Button type='link' onClick={() => this.handel_edit(record)}>编辑</Button></Link>
                        <Popconfirm
                            title="确定要删除吗？"
                            okText="确定"
                            cancelText="取消"
                            onConfirm={() => this.handleDelete(record.code)}
                        >
                            <Button type="link" danger style={{ padding: "0" }}>
                                删除
                          </Button>
                        </Popconfirm>
                    </Space>
                },
            },
        ];
        return <Table columns={columns} dataSource={this.props.data} bordered rowKey={(text, record) => text.id} scroll={{ x: 1500, y: 520 }} size="small"/>
    }
    handel_getData=()=>{
        this.$axios.get('/manager/api/getAllOrganizationList').then((res) => {
            const { home_get } = this.props;
            let new_list = {};
            [].push.apply(new_list, res.organizationList);
            home_get(new_list);

        }).catch((err) => {
            console.log(err);
        })
    }

    handel_edit = (e) => {
        const { home_edit } = this.props;
        home_edit(e)
    }
    handleDelete = (num) => {
        this.$axios.get(`/manager/api/deleteOrganizationr/${num}`).then((res) => {
            this.handel_getData()
        }).catch((err) => {
            console.log(err);
        })
    }
}

export default connect((state) => ({ ...state.custom }), action.custom)(index);